package com.rr.controller;

import cn.dev33.satoken.util.SaResult;
import com.rr.entity.FormatEntity;
import com.rr.prompt.SystemPrompt;
import com.rr.tools.SystemTools;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("chatAi")
public class ChatAiController {
    @Resource
    private ChatClient serviceChatClient;
    @RequestMapping("aicrud")
    public SaResult aicrud(String message) {

//        "查询moduleName为‘订单管理’的数据"
        FormatEntity entity = serviceChatClient.prompt().system( SystemPrompt.SERVICE_PROMPT)
                .user(prompt -> prompt
                        .text(SystemPrompt.SERVICE_PROMPT)
                        .param("user", message)
                )
                .call()
                .entity(FormatEntity.class);
        entity.getData().forEach(System.out::println);
         return SaResult.ok()
                 .setData(entity.getData())
                 .set("content", entity.getContent())
                 .set("moduleUrl", entity.getModelUrl());

    }


}
